<?php
class UsuariosController extends AppController {

	var $name = 'Usuarios';
	var $scaffold;
	
	function login()
		{
		$this->set('error', false);
		if (!empty($this->data))
		{
			print_r($this->data);
			$someone = $this->Usuario->findByUsername($this->data['Usuario']['username']);

            if(!empty($someone['Usuario']['password']) && $someone['Usuario']['password'] == $this->data['Usuario']['password'])
            {
                // Note: hopefully your password in the DB is hashed,
                // so your comparison might look more like:
                // md5($this->data['User']['password']) == ...

                $this->Session->write('Usuario', $someone['Usuario']);

                // Now that we have them stored in a session, forward them on
                // to a landing page for the application.

                $this->redirect('/quinielas');
            }
            // Else, they supplied incorrect data:
            else
            {
                // Remember the $error var in the view? Let's set that to true:
                $this->set('error', true);
                $this->Session->delete('Usuario');
            }
        }
    }

    function logout()
    {
        // Redirect users to this action if they click on a Logout button.
        // All we need to do here is trash the session information:

        $this->Session->delete('Usuario');

        // And we should probably forward them somewhere, too...
     
        $this->redirect('/');
    }
	
}

?>